package 集合;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;

public class TestCollection {
    public static void main(String[] args) {
        Collection<Integer> c = new ArrayList<Integer>();//多态+泛型(约束)+引用类型
        c.add(1);
        c.add(2);
        c.add(3);
        c.add(4);
        System.out.println(c);//[1, 2, 3, 4]
         //直接调用迭代器方法
        Iterator<Integer> it = c.iterator();// c.iterator();
        while(it.hasNext()){//it.hasNext()
            Integer next = it.next();//it.next()
            System.out.println(next);//1 2 3 4
        }


    }
}
